import { Project, ResponseProject } from '@entities/Projects'
import { rtkApi } from './rtkApi'

const projectApi = rtkApi.enhanceEndpoints({ addTagTypes: ['projects'] }).injectEndpoints({
  endpoints: (build) => ({
    createProject: build.mutation<Project, Omit<Project, 'id'>>({
      invalidatesTags: ['projects'],
      query: (project) => ({
        body: project,
        method: 'POST',
        url: 'projects/new-project',
      }),
    }),
    getProjects: build.query<ResponseProject[], void>({
      providesTags: ['projects'],
      query: () => 'projects',
    }),
  }),
})

export const { useCreateProjectMutation, useGetProjectsQuery } = projectApi
